package com.ly.im.controller;

import com.ly.im.annotaion.LoginUser;
import com.ly.im.pojo.Apply;
import com.ly.im.pojo.Friend;
import com.ly.im.pojo.User;
import com.ly.im.service.ApplyService;
import com.ly.im.service.FriendService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @Author LY
 * @create 2024/2/2 15:06
 * @Description 好友
 */
@RestController
@RequestMapping("/friend")
public class FriendController {

    @Resource
    private FriendService friendService;
    @Resource
    private ApplyService applyService;

    //获取好友列表
    @GetMapping("/list")
    public Object list(@LoginUser User user){
        return friendService.list(user.getId());
    }

    //添加好友
    @PostMapping("/add")
    public Object add(@LoginUser User user, @RequestBody Apply apply){
        apply.setUid(user.getId());
        return applyService.saveApply(apply);
    }

    @GetMapping("/getFriends")
    public Object getFriends(@LoginUser User user){
        return friendService.getFriends(user);
    }

    //同意
    @PostMapping("/agree")
    public Object agree(@LoginUser User user, @RequestBody Friend friend){
        friend.setUid(user.getId());
        return friendService.agree(friend);
    }

}
